/**
 * Created by Administrator on 2016/5/30.
 */

var m_nDataCount = 0;

$(document).ready(function()
{
    //addNewActivity();
    //getActivityInfo(10);
    //getActivityInfo(10);

    //var day = new Date();


   //2016-05-31 14:26:00
    console.debug("Init");
    var args = new Object();
    args = GetUrlParms();//获取参数数组

    $("#itemContainer").click(function()
    {
       // alert(111);
      // addNewActivity();

      //  getActivityInfo(10);


    })


    $("#hide").click(function()
    {
        //sendJson();
        // var data = {"rtmpMpdel":{"rows":[{"activityCategory":"001","activityId":"A20160531000013v","activityName":"HKTest","activityStatus":1,"belongUserId":"839712","coverImgUrl":"http://static.live.lecloud.com/images/default-pic.jpg","createTime":"20160531142745","description":"","endTime":"20160608142600","startTime":"20160531142600"},{"activityCategory":"012","activityId":"A2016053100000dl","activityName":"歌舞童心，爱我中华，首师大附小2016年6.1儿童节","activityStatus":1,"belongUserId":"839712","coverImgUrl":"http://i2.letvimg.com/lc06_live/201605/31/10/18/1464661128655new.png","createTime":"20160531094948","description":"6.1节学校组织了非常丰富的活动。\r\n1.“最靓民族服饰”Show。\r\n2.“歌舞童心 爱我中华”大联欢\r\n3.“最炫民族风”挑战赛。\r\n4.   欢乐泼水节","endTime":"20160603094900","startTime":"20160531094900"},{"activityCategory":"001","activityId":"A2016053000000ys","activityName":"123","activityStatus":3,"belongUserId":"839712","coverImgUrl":"http://static.live.lecloud.com/images/default-pic.jpg","createTime":"20160530143217","description":"","endTime":"20160531094840","startTime":"20160530143200"},{"activityCategory":"001","activityId":"A2016053000000w8","activityName":"334","activityStatus":3,"belongUserId":"839712","coverImgUrl":"","createTime":"20160530141137","description":"描述信息","endTime":"20160530141226","startTime":"20160530141225"},{"activityCategory":"001","activityId":"A2016053000000cg","activityName":"今天测试","activityStatus":3,"belongUserId":"839712","coverImgUrl":"","createTime":"20160530101257","description":"描述信息","endTime":"20160530141228","startTime":"20160530141227"},{"activityCategory":"001","activityId":"A201605290000052","activityName":"1122334","activityStatus":3,"belongUserId":"839712","coverImgUrl":"","createTime":"20160529015748","description":"描述信息","endTime":"20160530141230","startTime":"20160530141229"},{"activityCategory":"001","activityId":"A2016052700000yi","activityName":"9999","activityStatus":3,"belongUserId":"839712","coverImgUrl":"http://static.live.lecloud.com/images/default-pic.jpg","createTime":"20160527133614","description":"","endTime":"20160527135500","startTime":"20160527133600"},{"activityCategory":"001","activityId":"A2016051900001ku","activityName":"1234","activityStatus":3,"belongUserId":"839712","coverImgUrl":"http://static.live.lecloud.com/images/default-pic.jpg","createTime":"20160519155753","description":"","endTime":"20160519170146","startTime":"20160519155700"},{"activityCategory":"001","activityId":"A2016051900001jk","activityName":"123","activityStatus":3,"belongUserId":"839712","coverImgUrl":"http://static.live.lecloud.com/images/default-pic.jpg","createTime":"20160519154911","description":"","endTime":"20160519155700","startTime":"20160519154800"}],"total":9}}

       // var data = {"StreamInfo":{"startTime":"1463644620000","endTime":"1463648506000","liveNum":1,"lives":[{"bakPullUrl":"","machine":"1","pullUrl":"","pushUrl":"rtmp://w.gslb.lecloud.com/live/201605193000001v299?sign=ca4504065cf46c1f6538689c2d1973ce&tm=20160601124816","status":"0","streamId":"201605193000001v299","streamStatus":"2"}]}}

    })

});
function GetUrlParms() {
    var args = new Object();
    console.debug("GetUrlParms");
    var query = location.search.substring(1); //获取查询串
    console.debug(query);
    var pairs = query.split("&"); //在逗号处断开
    for (var i = 0; i < pairs.length; i++) {
        var pos = pairs[i].indexOf('='); //查找name=value
        if (pos == -1) continue; //如果没有找到就跳过
        var argname = pairs[i].substring(0, pos); //提取name
        console.debug(argname);
        var value = decodeURIComponent(pairs[i].substring(pos + 1)); //提取value
        console.debug(value);
        args[argname] = unescape(value); //存为属性
    }
    return args;
}
function addNewActivity(jsonData)
{

    var data = {"rtmpMpdel":{"rows":[{"activityCategory":"001","activityId":"A20160531000013v","activityName":"HKTest","activityStatus":1,"belongUserId":"839712","coverImgUrl":"http://static.live.lecloud.com/images/default-pic.jpg","createTime":"20160531142745","description":"","endTime":"20160608142600","startTime":"20160531142600"},{"activityCategory":"012","activityId":"A2016053100000dl","activityName":"歌舞童心，爱我中华，首师大附小2016年6.1儿童节","activityStatus":1,"belongUserId":"839712","coverImgUrl":"http://i2.letvimg.com/lc06_live/201605/31/10/18/1464661128655new.png","createTime":"20160531094948","description":"6.1节学校组织了非常丰富的活动。\r\n1.“最靓民族服饰”Show。\r\n2.“歌舞童心 爱我中华”大联欢\r\n3.“最炫民族风”挑战赛。\r\n4.   欢乐泼水节","endTime":"20160603094900","startTime":"20160531094900"},{"activityCategory":"001","activityId":"A2016053000000ys","activityName":"123","activityStatus":3,"belongUserId":"839712","coverImgUrl":"http://static.live.lecloud.com/images/default-pic.jpg","createTime":"20160530143217","description":"","endTime":"20160531094840","startTime":"20160530143200"},{"activityCategory":"001","activityId":"A2016053000000w8","activityName":"334","activityStatus":3,"belongUserId":"839712","coverImgUrl":"","createTime":"20160530141137","description":"描述信息","endTime":"20160530141226","startTime":"20160530141225"},{"activityCategory":"001","activityId":"A2016053000000cg","activityName":"今天测试","activityStatus":3,"belongUserId":"839712","coverImgUrl":"","createTime":"20160530101257","description":"描述信息","endTime":"20160530141228","startTime":"20160530141227"},{"activityCategory":"001","activityId":"A201605290000052","activityName":"1122334","activityStatus":3,"belongUserId":"839712","coverImgUrl":"","createTime":"20160529015748","description":"描述信息","endTime":"20160530141230","startTime":"20160530141229"},{"activityCategory":"001","activityId":"A2016052700000yi","activityName":"9999","activityStatus":3,"belongUserId":"839712","coverImgUrl":"http://static.live.lecloud.com/images/default-pic.jpg","createTime":"20160527133614","description":"","endTime":"20160527135500","startTime":"20160527133600"},{"activityCategory":"001","activityId":"A2016051900001ku","activityName":"1234","activityStatus":3,"belongUserId":"839712","coverImgUrl":"http://static.live.lecloud.com/images/default-pic.jpg","createTime":"20160519155753","description":"","endTime":"20160519170146","startTime":"20160519155700"},{"activityCategory":"001","activityId":"A2016051900001jk","activityName":"123","activityStatus":3,"belongUserId":"839712","coverImgUrl":"http://static.live.lecloud.com/images/default-pic.jpg","createTime":"20160519154911","description":"","endTime":"20160519155700","startTime":"20160519154800"}],"total":9}}

    var jsonData = eval(data);//接收到的数据转化为JQuery对象，由JQuery为我们处理

    $.each(jsonData, function (rootName, info)
    {
        if(rootName == "rtmpMpdel")
        {
            $.each(info, function (name, value) {

                if(name  == "rows")
                {
                    $.each(value, function (nameobject, value1) {

                        var activityCategory = value1.activityCategory;

                        //alert(value1.activityId);

                        m_nDataCount++;

                        var nodeactivityId = value1.activityId + "_"+m_nDataCount.toString();

                        var node = document.getElementById("itemContainer");
                        var trNode = document.createElement("tr");
                        //trNode.innerHTML="1111111111111";
                        trNode.setAttribute("id",nodeactivityId);

                        //td header info
                        var tdTitleNode = document.createElement("td");
                        trNode.appendChild(tdTitleNode);

                        //I - 标签
                        var tdTitleNodeILabel = document.createElement("i");
                        tdTitleNodeILabel.setAttribute("class","arrow-xxl-l");
                        tdTitleNode.appendChild(tdTitleNodeILabel);

                        //dl标签
                        var tdTitleNodeDl = document.createElement("dl");
                        tdTitleNodeDl.setAttribute("class","date-info");
                        tdTitleNode.appendChild(tdTitleNodeDl);


                        var data = value1.startTime;

                        var year =  data.substring(0,4);
                        var month =  data.substring(4,6);
                        var day=  data.substring(6,8);

                        var hour =  data.substring(8,10);
                        var minutes =  data.substring(10,12);
                       // var second=  data.substring(12,14);
                        var data_sp = year+"-"+month;

                        data_sp  = data_sp+"-"+day;

                        var time_sp = hour+":"+minutes;

                        //time_sp  = time_sp+":"+second;


                        //dt标签
                        var tdTitleNodeDt = document.createElement("dt");
                        tdTitleNodeDt.setAttribute("class","day");
                        tdTitleNodeDt.innerHTML=data_sp;
                        tdTitleNodeDl.appendChild(tdTitleNodeDt);

                        //dd标签
                        var tdTitleNodeDd = document.createElement("dd");
                        tdTitleNodeDd.setAttribute("class","time");



                        //dd span标签
                        var tdTitleNodeDdSpan = document.createElement("span");
                        tdTitleNodeDdSpan.setAttribute("class","time-clock");
                        tdTitleNodeDd.appendChild(tdTitleNodeDdSpan);
                        tdTitleNodeDdSpan.innerHTML=time_sp;
                        tdTitleNodeDl.appendChild(tdTitleNodeDd);

                        //dd_2标签
                        var tdTitleNodeDd_2 = document.createElement("dd");
                        tdTitleNodeDd_2.setAttribute("class","date-input");

                        //inputElement 标签
                        var inputElement =  document.createElement("input");
                        inputElement.setAttribute("type","text");
                        inputElement.setAttribute("value",value1.startTime);
                        inputElement.setAttribute("data-activityid",value1.activityId);
                        inputElement.setAttribute("data-oldtime",value1.startTime);
                        tdTitleNodeDd_2.appendChild(inputElement);
                        tdTitleNodeDl.appendChild(tdTitleNodeDd_2);

                        //td title info
                        var tdTitleNodeInfo = document.createElement("td");
                        var ptdinfo= document.createElement("p");
                        ptdinfo.setAttribute("class","link-blue-txt active-info");

                        var atdinfo= document.createElement("a");
                        atdinfo.setAttribute("href","javascript:;");
                        atdinfo.innerHTML = value1.description;
                        tdTitleNodeInfo.appendChild(ptdinfo);
                        ptdinfo.appendChild(atdinfo);
                     //   tdTitleNodeInfo.appendChild(atdinfo);
                        trNode.appendChild(tdTitleNodeInfo);


                        //td place
                        var tdplace = document.createElement("td");
                        tdplace.innerHTML = value1.activityName;
                        trNode.appendChild(tdplace);

                        //td type
                        var tdtype = document.createElement("td");
                        tdtype.innerHTML = value1.activityName;
                        trNode.appendChild(tdtype);

                        //td state
                        var tdstate = document.createElement("td");
                        var atdtype = document.createElement("span");
                        atdtype.setAttribute("class","color-onlive");
                        atdtype.innerHTML = "已开始";
                        tdstate.appendChild(atdtype);
                        trNode.appendChild(tdstate);

                        //td content
                        var tdcontent = document.createElement("td");

                        tdcontent.setAttribute("class","td-width-align");
                        tdcontent.setAttribute("style","width:auto;text-align:center !important");
                        //td content div
                        var divtdcontent = document.createElement("div");
                        divtdcontent.setAttribute("style","margin-left:30%;");
                        divtdcontent.setAttribute("class","manager");
                        var adivtdcontent = document.createElement("a");

                        adivtdcontent.setAttribute("class","pad-for-right");
                        adivtdcontent.setAttribute("href","javascript:;");
                        adivtdcontent.setAttribute("data-target","#videoModal");
                        adivtdcontent.setAttribute("data-toggle","modal");
                        adivtdcontent.setAttribute("onclick","previewActivity('A201606010000125')");

                        adivtdcontent.innerHTML = "预览";

                        var adivtdcontent_1 = document.createElement("a");
                        adivtdcontent_1.setAttribute("class","pad-for-right color-over");
                        adivtdcontent_1.innerHTML = "录制";

                        var adivtdcontent_2 = document.createElement("a");
                        adivtdcontent_2.setAttribute("class","pad-for-right");
                        adivtdcontent_2.innerHTML = "停止";

                        var adivtdcontent_3 = document.createElement("a");
                        adivtdcontent_3.setAttribute("class","pad-for-right");
                        adivtdcontent_3.innerHTML = "修改";


                        divtdcontent.appendChild(adivtdcontent);
                        divtdcontent.appendChild(adivtdcontent_1);
                        divtdcontent.appendChild(adivtdcontent_2);
                        divtdcontent.appendChild(adivtdcontent_3);
                        tdcontent.appendChild(divtdcontent);

                        trNode.appendChild(tdcontent);

                        node.appendChild(trNode);
                    });
                }

            });
        }

    });



}

function createActivityName(activityName,startTime,coverImgUrl,description,liveNum,codeRateTypes,needRecord,needTimeShift,activityCategory)
{
    //params.put("activityName", requestM.getActivityName());
    //params.put("startTime", requestM.getStartTime());
    //params.put("endTime", requestM.getEndTime());
    //params.put("coverImgUrl", requestM.getCoverImgUrl());
    //params.put("description", requestM.getDescription());
    //params.put("liveNum", requestM.getLiveNum());
    //params.put("codeRateTypes", requestM.getCodeRateTypes());
    //params.put("needRecord", requestM.getNeedRecord());
    //params.put("needTimeShift", requestM.getNeedTimeShift());
    //params.put("activityCategory", requestM.getActivityCategory());

    var request = {
        activityName:activityName,
        startTime:startTime,
        endTime:endTime,
        coverImgUrl:coverImgUrl,
        description:description,
        liveNum:liveNum,
        codeRateTypes:codeRateTypes,
        needRecord:needRecord,
        needTimeShift:needTimeShift,
        activityCategory:activityCategory

    };


    var json = JSON.stringify(request);


    $.ajax({
        url: "http://123.59.125.74:8080/leapt-console/json/user/public/createRTMPstreamming.json",
        type: 'POST',
        data: json,
        dataType: 'JSON',
        contentType : 'application/json',
        success: function (data) {

            //接收到的数据转化为JQuery对象，由JQuery为我们处理
            var jsonData = eval(data);

        },
        Error: function (xhr, error, exception) {
            // handle the error.
            alert(exception.toString());
        }
    });
}


function getActivityidInfoById(activityid)
{

    var activityid  = "A2016051900001ku";

    var request = {
        activityId:activityid
    };

    var json = JSON.stringify(request);


    $.ajax({
        url: "http://localhost:8080/leapt-console/json/user/public/getRTMPAddress.json",
        type: 'POST',
        data: json,
        dataType: 'JSON',
        contentType : 'application/json',
        success: function (data) {

            var jsonData = eval(data);//接收到的数据转化为JQuery对象，由JQuery为我们处理

            $.each(jsonData, function (rootName, info)
            {
                if(rootName == "StreamInfo")
                {
                    $.each(info, function (name, value) {

                        if(name  == "lives")
                        {
                            $.each(value, function (nameobject, value1) {

                                alert(value1.pushUrl);
                            });
                        }

                    });
                }

            });

        },
        Error: function (xhr, error, exception) {
            // handle the error.
            alert(exception.toString());
        }
    });
}



function getActivityInfo(offset) {

    var request = {
        activityId: '111',
        startTime: '111',
        endTime: '111',
        coverImgUrl: '111',
        description: '111',
        codeRateTypes: '111',
        needRecord: '111',
        needTimeShift: '111',
        activityCategory: '111',
    }
    //调用了jquery.json 库
    // var encoded = $.toJSON(request);

    var json = JSON.stringify(request);


    $.ajax({
        url: "http://123.59.125.74:8080/leapt-console/json/user/public/getAllRTMPstreamming.json",
        type: 'POST',
        data: json,
        dataType: 'JSON',
        contentType : 'application/json',
        success: function (data) {

           //var data = {"rtmpMpdel":{"rows":[{"activityCategory":"001","activityId":"A20160531000013v","activityName":"HKTest","activityStatus":1,"belongUserId":"839712","coverImgUrl":"http://static.live.lecloud.com/images/default-pic.jpg","createTime":"20160531142745","description":"","endTime":"20160608142600","startTime":"20160531142600"},{"activityCategory":"012","activityId":"A2016053100000dl","activityName":"歌舞童心，爱我中华，首师大附小2016年6.1儿童节","activityStatus":1,"belongUserId":"839712","coverImgUrl":"http://i2.letvimg.com/lc06_live/201605/31/10/18/1464661128655new.png","createTime":"20160531094948","description":"6.1节学校组织了非常丰富的活动。\r\n1.“最靓民族服饰”Show。\r\n2.“歌舞童心 爱我中华”大联欢\r\n3.“最炫民族风”挑战赛。\r\n4.   欢乐泼水节","endTime":"20160603094900","startTime":"20160531094900"},{"activityCategory":"001","activityId":"A2016053000000ys","activityName":"123","activityStatus":3,"belongUserId":"839712","coverImgUrl":"http://static.live.lecloud.com/images/default-pic.jpg","createTime":"20160530143217","description":"","endTime":"20160531094840","startTime":"20160530143200"},{"activityCategory":"001","activityId":"A2016053000000w8","activityName":"334","activityStatus":3,"belongUserId":"839712","coverImgUrl":"","createTime":"20160530141137","description":"描述信息","endTime":"20160530141226","startTime":"20160530141225"},{"activityCategory":"001","activityId":"A2016053000000cg","activityName":"今天测试","activityStatus":3,"belongUserId":"839712","coverImgUrl":"","createTime":"20160530101257","description":"描述信息","endTime":"20160530141228","startTime":"20160530141227"},{"activityCategory":"001","activityId":"A201605290000052","activityName":"1122334","activityStatus":3,"belongUserId":"839712","coverImgUrl":"","createTime":"20160529015748","description":"描述信息","endTime":"20160530141230","startTime":"20160530141229"},{"activityCategory":"001","activityId":"A2016052700000yi","activityName":"9999","activityStatus":3,"belongUserId":"839712","coverImgUrl":"http://static.live.lecloud.com/images/default-pic.jpg","createTime":"20160527133614","description":"","endTime":"20160527135500","startTime":"20160527133600"},{"activityCategory":"001","activityId":"A2016051900001ku","activityName":"1234","activityStatus":3,"belongUserId":"839712","coverImgUrl":"http://static.live.lecloud.com/images/default-pic.jpg","createTime":"20160519155753","description":"","endTime":"20160519170146","startTime":"20160519155700"},{"activityCategory":"001","activityId":"A2016051900001jk","activityName":"123","activityStatus":3,"belongUserId":"839712","coverImgUrl":"http://static.live.lecloud.com/images/default-pic.jpg","createTime":"20160519154911","description":"","endTime":"20160519155700","startTime":"20160519154800"}],"total":9}}

            var jsonData = eval(data);//接收到的数据转化为JQuery对象，由JQuery为我们处理


            addNewActivity(data);

            //$.each(jsonData, function (rootName, info)
            //{
            //    if(rootName == "rtmpMpdel")
            //    {
            //        $.each(info, function (name, value) {
            //
            //            if(name  == "rows")
            //            {
            //                $.each(value, function (nameobject, value1) {
            //
            //                    alert(value1.activityCategory);
            //
            //
            //                });
            //            }
            //
            //        });
            //    }
            //
            //});

        },
        Error: function (xhr, error, exception) {
            // handle the error.
            alert(exception.toString());
        }
    });
}